package com.jzo2o.health.listener;

import cn.hutool.core.date.DateTime;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.health.model.domain.ReservationSetting;
import com.jzo2o.health.model.dto.request.ReservationSettingUpsertReqDTO;
import com.jzo2o.health.model.excel.ReservationImportData;
import com.jzo2o.health.service.IReservationSettingService;
import com.jzo2o.health.service.impl.ReservationSettingServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.DataFormatter;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/*
 *   Description AnalysisEventListenerImpl
 *   @author zhangyan
 *   @time   2024/12/14
 */
@Slf4j
public class AnalysisEventListenerImpl extends AnalysisEventListener<ReservationImportData> {

    private IReservationSettingService reservationSettingService;
    public AnalysisEventListenerImpl () {
    }
    public AnalysisEventListenerImpl(IReservationSettingService reservationSettingService){
        this.reservationSettingService=reservationSettingService;
    }
    @Override
    public void invoke(ReservationImportData data, AnalysisContext analysisContext) {
        // 插入数据库的逻辑
//        ReservationSetting reservationSetting = new ReservationSetting();
//        reservationSetting.setOrderDate(LocalDate.parse(data.getDate()));
//        reservationSetting.setNumber(data.getNumber());
        ReservationSettingUpsertReqDTO reservationSettingUpsertReqDTO = new ReservationSettingUpsertReqDTO();
        reservationSettingUpsertReqDTO.setNumber(data.getNumber());
        reservationSettingUpsertReqDTO.setOrderDate(LocalDate.parse(data.getDate()));
        reservationSettingService.editNumberByDate(reservationSettingUpsertReqDTO);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("所有数据解析完成！");
    }
}
